package com.wang.controller;

import com.wang.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class Encoding {


    //前端和后端数据的请求和返回

    //方式一（属性名都相同）
    //localhost8080://项目名/t1?name=qwe
    @RequestMapping("/t1")
    public String test1(String name, Model model){

        model.addAttribute("msg",name);

        return "test";
    }

    //方式二(属性名不相同)
    //localhost8080://项目名/t2?username=qwe
    //@RequestParam("username") 代表从前端获得数据
    @RequestMapping("/t2")
    public String test2(@RequestParam("username") String name, Model model){

        model.addAttribute("msg",name);

        return "test";
    }


    //用对象来传递参数(属性名必须一致)
    //localhost:8080//项目名/t3?id=1&name=yuyy&age=18
    @RequestMapping("/t3")
    public String test3(User user, Model model){
        System.out.println(user);
        return "test";
    }



    //乱码问题(我们使用中文)
    @RequestMapping("/t4")
    public String test4(String name, Model model){
        
        model.addAttribute("msg",name);

        return "test";
    }
}
